Java中以指定编码方式读取字符流 您所在的位置:网站首页 ready now王琳凯 Java中以指定编码方式读取字符流

Java中以指定编码方式读取字符流

2022-05-28 16:30| 来源: 网络整理| 查看: 265

Java中可以以指定的编码方式读取字符流,比如utf-8,utf-16,utf-32和gbk等,也可以自己制定解码算法。

这里涉及的一个class就是InputStreamReader,它用于在字节流上建立字符流。

构造方式有:

public InputStreamReader(InputStream in)

public InputStreamReader(InputStream in,String enc)

public InputStreamReader(InputStream in,CharsetDecoder dec)

File f=new File("/home/tobacco/Downloads/MESSAGE.txt");           try {               try {   BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(f),"gbk"));  

} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有